package com.example.smartcity.ui.dashboard;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Adapter.ViolationListAdapter;
import com.example.smartcity.ui.Bean.ViolationBean;
import com.example.smartcity.ui.Tools.OkHttpUtils;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class ViolationList extends AppCompatActivity {

    private ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_violation_list);
        listView = findViewById(R.id.listView);
        initView();
    }
    public void setBack(View view){
        this.finish();
    }
    public void initView(){
        OkHttpUtils.getCall(getIntent().getStringExtra("newUrl")).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("TAG", "onFailure: "+e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String Json = response.body().string();
                Log.d("TAG", "onResponse: "+Json);
                ViolationBean bean = new Gson().fromJson(Json,ViolationBean.class);
                List<ViolationBean.RowsBean> list = bean.getRows();
                listView.post(new Runnable() {
                    @Override
                    public void run() {
                        listView.setAdapter(new ViolationListAdapter(getBaseContext(),R.layout.violationitemlayout,list));
                    }
                });
            }
        });

    }
}